<!-- Content Wrapper. Contains page content -->
<div class="content-wrapper">
  <!-- Content Header (Page header) -->
  <section class="content-header">
    <h1>
      应用列表
      <small></small>
    </h1>
    <ol class="breadcrumb">
      <li><a href="#"><i class="fa fa-dashboard"></i> Level</a></li>
      <li class="active">Here</li>
    </ol>
  </section>

  <!-- Main content -->
  <section class="content">

    <div class="row">
      <div class="col-xs-12">

        <div class="box">
          <!--<div class="box-header">
            <h3 class="box-title">应用列表</h3>
          </div>&lt;!&ndash; /.box-header &ndash;&gt;-->
          <div class="box-body">
            <table id="data_table" class="table table-bordered table-striped">
              <thead>
              <tr>
                <th>应用</th>
                <th>描述</th>
                <th>负责人</th>
                <th>类型</th>
                <th style="width: 108px">操作</th>
              </tr>
              </thead>
              <tbody>
              <% @apps.each do |app| %>
                  <tr>
                    <td><%= app.name %></td>
                    <td><%= app.describe %></td>
                    <td><%= app.owner %></td>
                    <td><%= app.app_type %></td>
                    <td>
                      <div class="btn-group">
                        <button type="button" class="btn btn-info table_btn" onclick="location.href='/deploy/<%= app.id %>'">上线</button>
                        <!--<button type="submit" class="btn btn-warning table_btn" onclick="location.href='/operate/<%= app.id %>'">操作</button>-->
                        <div class="btn-group">
                          <button type="button" class="btn btn-info dropdown-toggle table_btn" data-toggle="dropdown" aria-expanded="false">
                            <span class="caret"></span>
                          </button>
                          <ul class="dropdown-menu">
                            <li><a href="/deploy/rollback/<%= app.id %>">回滚</a></li>
                            <li><a href="/deploy/restart/<%= app.id %>">重启</a></li>
                            <li><a href="/deploy/start/<%= app.id %>">启动</a></li>
                            <li><a href="/deploy/stop/<%= app.id %>">关闭</a></li>
                            <li><a href="/deploy/status/<%= app.id %>">状态查询</a></li>
                            <li><a href="/deploy/view_version/<%= app.id %>">版本查询</a></li>
                          </ul>
                        </div>
                      </div>
                    </td>
                  </tr>
              <% end %>
              </tbody>
            </table>
          </div>
          <!-- /.box-body -->
        </div>
        <!-- /.box -->
      </div>
      <!-- /.col -->
    </div>
    <!-- /.row -->
  </section>
  <!-- /.content -->
</div><!-- /.content-wrapper -->

<%= form_tag do %>
    <input type="hidden" name="env" value="<%= Rails.env == "production" ? "生产" : "上线前" %>"/>
<% end %>
<script type="text/javascript">
    $(function () {
        //列表排序脚本
        $("#data_table").dataTable({
            "bSort": true
        });
    })


    isFirstClick = true
    function rollback(id) {
        <% if Rails.env == "production" %>
        //生产环境部署要求额外确认
        re = window.confirm('该操作会回滚生产环境，确认继续吗？')
        if (!re) {
            return
        }
        re = window.confirm('该操作会回滚生产环境，确认继续吗？')
        if (!re) {
            return
        }
        <% end %>
        //通过js防止重复提交
        if (isFirstClick) {
            isFirstClick = false
        } else {
            return false
        }

        $('form').attr('action', '/deploy/rollback/' + id).submit()
    }
</script>
